package com.wdl.fmnew.app.fragmentDemo;

import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.wdl.fmnew.R;
import com.wdl.fmnew.app.fragmentDemo.demo01.Demo01Fragment;
import com.wdl.fmnew.app.fragmentDemo.demo02.Demo02Fragment;
import com.wdl.fmnew.core.base.BaseActivity;

import javax.inject.Inject;

import butterknife.OnClick;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Created by wdl on 2017/9/19.
 */

public class DemoFragmentActivity extends BaseActivity {
    @Inject
    Demo01Fragment demo01Fragment;

    @Inject
    Demo02Fragment demo02Fragment;

    @Override
    protected int getContentView() {
        return R.layout.activity_fragment;
    }

    @Override
    protected void loadView() {

    }

    @OnClick(R.id.button_01)
    public void clickFragment01() {

        addFragmentToActivity(getSupportFragmentManager(),
                demo01Fragment, R.id.contentFrame);

    }

    @OnClick(R.id.button_02)
    public void clickFragment02() {

        addFragmentToActivity(getSupportFragmentManager(),
                demo02Fragment, R.id.contentFrame);

    }

    public static void addFragmentToActivity(@NonNull FragmentManager fragmentManager,
                                             @NonNull Fragment fragment, int frameId) {
        checkNotNull(fragmentManager);
        checkNotNull(fragment);
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(frameId, fragment);
        transaction.commit();
    }
}
